package org.example.rtc.controller;

import cn.dev33.satoken.stp.StpUtil;
import lombok.RequiredArgsConstructor;
import org.example.rtc.model.entity.SpecialistInfo;
import org.example.rtc.model.entity.dto.R;
import org.example.rtc.service.SpecialistInfoService;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/specialist")
@RequiredArgsConstructor
public class SpecialistApi {

    private final SpecialistInfoService specialistInfoService;

    @GetMapping("/getAll")
    public R<List<SpecialistInfo>> getAllPat(@RequestHeader("Authorization") String token) {
        Object loginId = StpUtil.getLoginIdByToken(token);
        List<SpecialistInfo> specialistInfoList = specialistInfoService.list();
        if (CollectionUtils.isEmpty(specialistInfoList)) {
            return R.success();
        }else {
            specialistInfoList=specialistInfoList.stream()
                    .filter(e->!e.getExpertId().toString().equals(String.valueOf(loginId))).collect(Collectors.toList());
            return R.success(specialistInfoList);
        }
    }

    @GetMapping("/getAll/{id}")
    public R<SpecialistInfo> getById(@PathVariable("id") Long id){
        return R.success(specialistInfoService.getById(id));
    }

}
